home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 726-750 / 742 / icalc / docs / userguide < prev    next >
Text File  |  1995-03-18  |  38KB  |  1,123 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.                                ›3micalc ›0m›1mversion 2›0m.›1m1 
  16.  
  17.  
  18.  
  19.                      ›0mA complex-number expression language 
  20.  
  21.                          (C) 1991,1992 Martin W.Scott 
  22.                              All Rights Reserved.  
  23.  
  24.  
  25.  
  26.                                   User Guide 
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.      icalc                         User Guide                         icalc
  69.  
  70.  
  71.      ›1mIntroduction 
  72.  
  73.           ›0m›3micalc  ›0mis  a  terminal-based  calculator;  the  ›1mi ›0mstands for
  74.           ›1mimaginary›0m, denoting the fact that the calculator works  with
  75.           complex numbers.  There are many calculator programs for the
  76.           Amiga, but  to  my knowledge, none with this ability.  ›3micalc
  77.           ›0malso performs real (normal) calculations too,  and  you  can
  78.           completely ignore the complex number facility if you wish.  
  79.  
  80.           Version 2.0 of icalc introduced major additions, effectively
  81.           making ›3micalc  ›0ma  C-like  programming language.  However, you
  82.           can completely ignore these extensions if you shy away  from
  83.           programming.    In   light   of   this,  the  more  advanced
  84.           documentation is kept separate from the simple instructions,
  85.           in  the  'Advanced  Guide',  which  covers  such  topics  as
  86.           number-bases, programming constructs, arrays and scripts.  
  87.  
  88.  
  89.      ›1mComplex Numbers 
  90.  
  91.           ›0mA  complex number is made up of two components: a real part,
  92.           and an imaginary part.  The imaginary part is  just  a  real
  93.           number  multiplied by the special number i, which is defined
  94.           to be the square root of -1.  Thus, i*i = -1. This  may  all
  95.           seem very artificial, but it's not; complex numbers exist as
  96.           surely  as  real  numbers  do  (or  don't, depending on your
  97.           mathematical philosophy).  However, real numbers  seem  more
  98.           tangible  to  us,  since  we  use them (or approximations to
  99.           them) in our everyday life.  It is not the purpose  of  this
  100.           guide  to  teach you anything about complex numbers - if you
  101.           don't know about them, you probably don't need  to,  but  if
  102.           you  do  any  numerical  work,  you will probably still find
  103.           ›3micalc ›0museful, because real numbers are a subset  of  complex
  104.           numbers,  and  can thus be manipulated by this program as in
  105.           an ordinary calculator-type program.  Don't be put off  -  I
  106.           hardly  ever  need  to use complex numbers - I just like the
  107.           facility to be there for the odd  occasion  when  I  do  use
  108.           them.  
  109.  
  110.           In what follows, examples are indented.  Things you type are
  111.           preceded  by  a  '>'  prompt  sign, and output from ›3micalc ›0mis
  112.           further indented.  
  113.  
  114.  
  115.      ›1mExpressions 
  116.  
  117.           ›0m›3micalc ›0maccepts expressions in the  usual  form  for  computer
  118.           expressions, i.e.    multiplication must be explicitly shown
  119.           by '*', and function arguments enclosed within  parentheses.
  120.           The  exception  to  this is the method of inputing imaginary
  121.           parts of complex numbers.  If you want to enter the number 3
  122.           + 4i, you can type either 
  123.  
  124.                   > 3+4i
  125.  
  126.           or 
  127.  
  128.                   > 3+4*i
  129.  
  130.  
  131.      icalc                            -2-                       version 2.1
  132.  
  133.  
  134.      icalc                         User Guide                         icalc
  135.  
  136.  
  137.  
  138.           but ›3mnot 
  139.  
  140.                   ›0m> 3+i4        # this won't do...
  141.  
  142.           since this would give an ambiguous grammar - is  it  i*4  or
  143.           the variable "i4"?  
  144.  
  145.           In   almost   all   circumstances,  the  algebraic  "4i"  is
  146.           preferred, but there is one exception, exponentation "^". If
  147.           you want 3*i^3, you must type 
  148.  
  149.                   > 3*i^3
  150.  
  151.           and not 
  152.  
  153.                   > 3i^3
  154.  
  155.           The former gives the correct result, -3i, whilst the  latter
  156.           gives  -27i.  This  is  because  the  grammar sees "3i" as a
  157.           number   in   its   own   right,   and   not   an   implicit
  158.           multiplication.  
  159.  
  160.           NB:  Implicit  multiplication (leaving out '*' sign) is only
  161.           recognised in the case of a numerical multiple of i.  
  162.  
  163.           See the  appendices  for  the  complete  list  of  commands,
  164.           operators,   constants  and  builtin  functions  that  ›3micalc
  165.           ›0msupports.  
  166.  
  167.           Expressions are separated by newlines  or  semi-colons  ';'.
  168.           You may also split an expression over multiple lines using a
  169.           backslash  '\'  to  indicate  continuation to the next input
  170.           line.  Comments are introduced by '#', and the rest  of  the
  171.           input line  is  ignored.   You may also place comments after
  172.           backslashes.  
  173.  
  174.  
  175.      ›1mSample Expressions 
  176.  
  177.           ›0mBelow are a few examples of what ›3micalc ›0mwill accept.  
  178.  
  179.                   > x=4     # an assignment statement
  180.  
  181.           assigns to variable x the value 4.  
  182.  
  183.                   > # and now, two statements separated by a semi-colon
  184.                   > sqr(x); x*sqr(x);
  185.  
  186.           displays the values 16 and 64 (sqr(x)  returns  x*x).    The
  187.           next  example  demonstrates  a  problem  inherent in machine
  188.           calculations: 
  189.  
  190.                   > 2*sin(x)*cos(x) - sin(2*x)
  191.  
  192.           displays the value -2.22044604925e-16. The answer should  be
  193.           0, and indeed is very close to that.  The inaccuracy results
  194.           because  each  term has a value as close to the actual value
  195.  
  196.  
  197.      icalc                            -3-                       version 2.1
  198.  
  199.  
  200.      icalc                         User Guide                         icalc
  201.  
  202.  
  203.           as the computer's internal  representation  of  numbers  can
  204.           hold  (see the Advanced Guide for a small discussion of this
  205.           particular case).  
  206.  
  207.           You can change  the  number  of  significant  figures  ›3micalc
  208.           ›0mdisplays by the prec() function - see Appendix 4.  
  209.  
  210.  
  211.      ›1mStarting icalc 
  212.  
  213.           ›0m›3micalc ›0mmay be started from either the CLI or Workbench.  Once
  214.           started, ›3micalc ›0mwill process the file whose name is contained
  215.           in  the  environment  variable  ICALCINIT, defaulting to the
  216.           file "s:icalc.init" if no environment variable is  declared.
  217.           This initialization file may be used to extend the functions
  218.           available in  ›3micalc.    ›0mA  sample  file  is  given  in the S
  219.           directory of this distribution.  If running  under  AmigaDOS
  220.           1.3,  it  is  recommended  that you use NEWCON: or ConMan to
  221.           provide editing  and  history  facilities.    For  users  of
  222.           AmigaDOS  2.0,  the  normal CON: window has these facilities
  223.           built-in, and you may also add a close gadget.  
  224.  
  225.        CLI Usage 
  226.  
  227.           The synopsis for icalc is 
  228.  
  229.                   icalc [file-list]
  230.  
  231.           where file-list is a list of input files.  ›3micalc  ›0mwill  read
  232.           (process) the files in the list and exit.  If a file-list is
  233.           specified, ›3micalc ›0mwill assume that you do not wish to use the
  234.           program interactively.  If you do, you should specify one of
  235.           the files as a dash "-"; this is taken to mean "use standard
  236.           input".    If   no  file-list  is  given,  ›3micalc  ›0mstarts  an
  237.           interactive session.  You can obviously redirect output to a
  238.           file if you wish (and redirect input from a file,  but  this
  239.           is generally  unnecessary).    For example, if you wanted to
  240.           use definitions contained in a file  called  "stat.ic",  and
  241.           then type some expressions in at the terminal, you would use 
  242.  
  243.                   icalc stat.ic -
  244.  
  245.           to start  the  program.  Because the program makes extensive
  246.           use of recursion, I recommend you use a stack size of  about
  247.           20K when running ›3micalc.  
  248.  
  249.        ›0mWorkbench Usage 
  250.  
  251.           To  start  ›3micalc ›0mfrom the Workbench, simply double-click its
  252.           icon.   You  may  also  pass  arguments  (definition/command
  253.           files)  to ›3micalc ›0min the usual Workbench manner (shift-select
  254.           etc.).  ›3micalc ›0mwill then  open  a  window  on  the  Workbench
  255.           screen for  an  interactive  session.    You can specify the
  256.           window to be opened by modifying the WINDOW tooltype  (click
  257.           once on the ›3micalc ›0micon, and select "Info" from the Workbench
  258.           menu).  By default, this is a CON: window.  (As noted above,
  259.           AmigaDOS 1.3 users could alter this to a NEWCON: window).  
  260.  
  261.  
  262.  
  263.      icalc                            -4-                       version 2.1
  264.  
  265.  
  266.      icalc                         User Guide                         icalc
  267.  
  268.  
  269.           You  may  also  set  the default tool of a definition file's
  270.           project icon to be ›3micalc.  ›0mThen simply double  clicking  the
  271.           project  icon  will  launch  ›3micalc  ›0mand  read the definition
  272.           file.  Remember, however, to set the project icon's stack to
  273.           20000, or you may get a stack overflow error.  
  274.  
  275.        Exiting icalc 
  276.  
  277.           To end an interactive session of ›3micalc ›0m(from either  CLI  or
  278.           Workbench) use  the  command "quit" or "exit".  You can also
  279.           type ^\ (press the control key and '\' simultaneously).   If
  280.           running  under  AmigaDOS  2.0,  you  can  use  the  window's
  281.           close-gadget.  
  282.  
  283.  
  284.      ›1mVariables 
  285.  
  286.           ›0mVariables in ›3micalc ›0mcan be named arbitrarily, as long  as  no
  287.           name  conflicts  with a pre-defined symbol name, such as sin
  288.           or PI. The standard conventions apply: the  first  character
  289.           must  be  a  letter  or  underscore, followed by a string of
  290.           letters, digits and underscores.  Case IS significant.  
  291.  
  292.           Variables are introduced by using them;  If  a  variable  is
  293.           used  before  it  has been initialized (i.e. has had a value
  294.           assigned to it), ›3micalc ›0mwill warn the user and use the  value
  295.           zero.  Assignments can appear anywhere in an expression, and
  296.           are  in  fact  expressions  in  their  own  right (as in the
  297.           programming language C).  So, you can do things like 
  298.  
  299.                   > apple = banana = apricot = 34
  300.  
  301.           to assign the value  34  to  all  these  variables.    Since
  302.           assignments   are   expressions,   their   value  being  the
  303.           assignment value, you can also do 
  304.  
  305.                   > apple = sqr(banana = 12)
  306.  
  307.           which assigns the value 12 to "banana", and 144 to  "apple".
  308.           You can of course assign new values to existing variables.  
  309.  
  310.  
  311.      ›1mConstants and ans 
  312.  
  313.           ›0m›3micalc ›0mcomes  with  several  predefined  constants, e.g.  PI,
  314.           GAMMA etc, which by convention are all in upper-case.    You
  315.           cannot assign a new value to a constant.  There is a special
  316.           constant,  "ans",  which isn't really a constant at all, but
  317.           is made so to prevent assignments to it.  "ans" contains the
  318.           value of the previously  evaluated  expression,  and  so  is
  319.           useful when splitting a calculation up into smaller chunks.  
  320.  
  321.                   > 1 + 2 + 3
  322.                           6
  323.                   > ans * 12
  324.                           72
  325.  
  326.           You can  also  use  it for recursive formulas.  For example,
  327.  
  328.  
  329.      icalc                            -5-                       version 2.1
  330.  
  331.  
  332.      icalc                         User Guide                         icalc
  333.  
  334.  
  335.           the logistic equation xnext = rx(1-x) for parameter r = 3.5,
  336.           initial x = 0.4 could be iterated as follows: 
  337.  
  338.                   > r = 3.5; 0.4          # initialize r and ans
  339.                           3.5
  340.                           0.4
  341.                   > r*ans*(1-ans)
  342.                           0.84
  343.                   > r*ans*(1-ans)
  344.                           0.4704
  345.                   > r*ans*(1-ans)
  346.                           0.87193344
  347.                   > r*ans*(1-ans)
  348.                           0.39082930673
  349.  
  350.           and so on.  Of course, you needn't use "ans" here; you could
  351.           just use assignments to "x", but it illustrates  the  point.
  352.           Note   that   once   the   necessary   variables  have  been
  353.           initialised, the same expression  is  evaluated  repeatedly.
  354.           Thus,  if  you  are using a window with history capabilities
  355.           you can save a lot of typing by pressing the up-arrow.  
  356.  
  357.           There are other ways to  perform  repeated  calculations  in
  358.           ›3micalc.   ›0mYou  can use so-called Special functions (explained
  359.           below), or the C-style looping constructs described  in  the
  360.           'Advanced Guide'.  
  361.  
  362.  
  363.      ›1mBuiltin Functions 
  364.  
  365.           ›0m›3micalc  ›0mcomes  with  many builtin functions, for example sin,
  366.           cos, sqrt, exp, ln etc.  There are  some  special  functions
  367.           for complex  numbers  too,  namely  Im,  Re, arg, norm.  All
  368.           functions take real or complex arguments, which can  be  any
  369.           expression,  although  in  some  cases,  the complex part is
  370.           discarded.  Consider 
  371.  
  372.                   > sin(12-3i)
  373.                           -5.40203477452 - 8.45362341558 i
  374.                   > asin(ans)
  375.                           -0.56637061436 - 3 i
  376.                   > sin(ans)
  377.                           -5.40203477452 - 8.45362341558 i
  378.  
  379.           Here we see a property of inverse  trigonometric  functions,
  380.           their  many-valuedness, due to their periodicity on the real
  381.           line.   The  function  asin  returns  a  value  in  its  PVR
  382.           (principal  value  range) as do all many-valued functions in
  383.           ›3micalc.  ›0mSee the 'Advanced Guide' for  exact  definitions  of
  384.           PVRs of the inverse trigonometric functions used in ›3micalc.  
  385.  
  386.           ›0mOther  functions  owe their many-valuedness to the fact that
  387.           the argument of a complex number is 2*PI-periodic. In  ›3micalc
  388.           ›0mthe argument always falls in the range -PI < arg <= PI.  
  389.  
  390.           Another  thing  to  bear in mind if you're not using complex
  391.           numbers is that expressions like 
  392.  
  393.  
  394.  
  395.      icalc                            -6-                       version 2.1
  396.  
  397.  
  398.      icalc                         User Guide                         icalc
  399.  
  400.  
  401.                   > ln(-1)
  402.  
  403.           return a value, 3.14159265359*i (PI*i) in this case.    (The
  404.           natural  logarithm  onto  the real line is defined for range
  405.           (0, +infinity)).  
  406.  
  407.  
  408.      ›1mUser›0m-›1mdefined Functions 
  409.  
  410.           ›0mUser-defined  functions  give  ›3micalc  ›0mits  flexibility   and
  411.           power.   Any  function  that  can  be  stated  as  a  normal
  412.           expression (or list of expressions) may  easily  be  defined
  413.           and used  like  a  builtin function.  In this document, only
  414.           very simple function definitions are explained.    Functions
  415.           more  akin  to  those in a computer program are described in
  416.           the 'Advanced Guide'.  
  417.  
  418.           Functions are defined  using  the  'func'  keyword,  in  the
  419.           following manner: 
  420.  
  421.                   func <name> ( <parameter-list> ) = <expr>
  422.  
  423.           so to define the function f(z) = sin(sqrt(z)), simply type 
  424.  
  425.                   > func f(z) = sin(sqrt(z))
  426.  
  427.           Note  that  z  is  ›3mlocal  ›0mto  the  function,  not  a  global
  428.           variable.  Thus, if z has been defined as a variable  before
  429.           defining f(z),  it  is  unaltered  when  you call f(z).  The
  430.           standard initiation file 'icalc.init' contains  many  simple
  431.           function  definitions,  and  you  may find it instructive to
  432.           examine it.  
  433.  
  434.           Multi-parameter functions may also be defined.  For example,
  435.           the volume of a right-circular cone is given by the formula 
  436.  
  437.                   volume = 1/3*PI*sqr(r)*h
  438.  
  439.           where r is the radius of the base, and h is  the  height  of
  440.           the cone.  We can define a function to compute the volume as
  441.           follows: 
  442.  
  443.                   > func conevol(r,h) = 1/3*PI*sqr(r)*h
  444.                   > conevol(1,3)
  445.                           3.14159265359
  446.  
  447.           It  is  also  possible  (though  of  limited use) to declare
  448.           functions that   take   no   parameters.      Examples    of
  449.           multi-parameter functions are given in the sample definition
  450.           files.  
  451.  
  452.           NB: As with most programming languages, don't write circular
  453.           definitions;  ›3micalc  ›0mdoes  not detect them, and will swiftly
  454.           run out of stack space.  
  455.  
  456.  
  457.  
  458.  
  459.  
  460.  
  461.      icalc                            -7-                       version 2.1
  462.  
  463.  
  464.      icalc                         User Guide                         icalc
  465.  
  466.  
  467.      ›1mSpecial Functions 
  468.  
  469.           ›0mCertain  builtin  functions  in  ›3micalc  ›0mare  called  ›3mspecial
  470.           ›0mbecause of the way they use their arguments.  Normally, when
  471.           you `call' a function, its arguments are first evaluated and
  472.           then the   function  is  called.    With  special  functions
  473.           however, the arguments are not evaluated;  this  means  that
  474.           the  expressions  themselves (and not just their values) can
  475.           be used by the function in a number of ways.  
  476.  
  477.           Special functions were introduced in version 1.1  of  ›3micalc.
  478.           ›0mbut  since  version  2.0, they have become largely redundant
  479.           (with one or two exceptions) due to the C-style  programming
  480.           constructs added.    However,  for non-programmers or people
  481.           who don't wish to use ›3micalc ›0mas a programming language,  they
  482.           do  provide a means for performing several common operations
  483.           which would otherwise prove difficult.  
  484.  
  485.           Some special functions take integers as  arguments;  if  you
  486.           supply  an  expression with a non-integral value, this value
  487.           will  be  stripped  of  its  imaginary  component,  and  the
  488.           remaining  real  number  rounded  to  the  nearest  integer.
  489.           Currently, the special functions are as follows.  
  490.  
  491.        Sum(var,upto,expr) 
  492.  
  493.           This command calculates finite sums.  The variable `var'  is
  494.           the index  of summation, with an optional assignment.  While
  495.           the value of the index is less than or equal to the value of
  496.           the upto argument, the value of expr is added to an internal
  497.           summation variable, which is initially zero.  Examples  will
  498.           help to clarify usage.  
  499.  
  500.           To  evaluate  the  sum  of  the  first  100  natural numbers
  501.           (naively) we could do 
  502.  
  503.                   > Sum(n=1,100,n)
  504.  
  505.           which gives the answer as  5050  (which  is  100/2*(100+1)).
  506.           Note the  initial assignment of 1 to n.  If no initial value
  507.           is specified, a value of zero is assumed (and  the  user  is
  508.           notified of  this).  When a summation is complete, the index
  509.           variable holds a value 1 greater than the value of upto.  We
  510.           can also use Sum() to  provide  approximations  to  infinite
  511.           sums.  
  512.  
  513.                   > Sum(n=1, 100, 1/sqr(n)) 
  514.                           1.63498390018
  515.  
  516.           Using  the  fact  that n will now hold the value 101, we can
  517.           continue the summation to 200 by the following: 
  518.  
  519.                   > ans + Sum(n, n+99, 1/sqr(n))
  520.                           1.63994654601
  521.  
  522.           and continue to obtain closer answers by repeating the  last
  523.           line, 
  524.  
  525.  
  526.  
  527.      icalc                            -8-                       version 2.1
  528.  
  529.  
  530.      icalc                         User Guide                         icalc
  531.  
  532.  
  533.                   > ans + Sum(n, n+99, 1/sqr(n))
  534.                           1.6416062829
  535.  
  536.           which is getting there (the infinite series sums to PI^2/6 =
  537.           1.64493406685).   One  last  example, to evaluate the sum of
  538.           the all even numbers upto 100.  
  539.  
  540.                   > Sum(n=1, 50, 2*n)
  541.                           2550
  542.  
  543.  
  544.        Prod(var,upto,expr) 
  545.  
  546.           This command calculates finite products, in an analogous way
  547.           to the Sum() special function.   Examples  will  demonstrate
  548.           its use.  
  549.  
  550.                   > Prod(n=1, 10, n)
  551.  
  552.           calculates  10!, which is 3628800. We can also use Prod() to
  553.           investigate  infinite  products,  although  care  should  be
  554.           taken.  Consider Wallis's product for PI/2: 
  555.  
  556.                   PI   2×2×4×4×6×6×...
  557.                   -- = ---------------
  558.                   2    1×3×3×5×5×7×...
  559.  
  560.           Here  the  product  is 2/1 * 2/3 * 4/3 * 4/5 * ... and so we
  561.           must  find  a  method  of  producing  the   numerators   and
  562.           denominators from  an  index.  It is easiest to evaluate the
  563.           product in  pairs  of  terms.    Thus,  for  each  term  our
  564.           numerator  will  be  sqr(2*n),  and  our denominator will be
  565.           (2*n-1)*(2*n+1) = sqr(2*n)-1.  Note that sqr(2*n) appears in
  566.           both the  numerator  and  denominator.    We  can  therefore
  567.           optimise  the  calculation  by using a temporary variable to
  568.           hold this value.  We proceed as follows: 
  569.  
  570.                   > Prod(n=1, 100, (t = sqr(2*n))/(t-1))
  571.                           1.56689374531
  572.                   > ans * Prod(n, n+99, (t = sqr(2*n))/(t-1))
  573.                           1.56883895048
  574.                   > ans * Prod(n, n+99, (t = sqr(2*n))/(t-1))
  575.                           1.56949005194
  576.  
  577.  
  578.        every(var,upto,expr) and vevery(var,upto,expr) 
  579.  
  580.           These functions preform more general iterations  than  Sum()
  581.           and Prod().    They  return the value of the last expression
  582.           evaluated, ie.   expr  evaluated  when  var  =  upto.    The
  583.           difference  between  every() and vevery() is that the latter
  584.           produces verbose output - it prints the value of  the  index
  585.           and the result of the expression for every iteration.  
  586.  
  587.           Example:   evaluate   sin(sin(...(sin(z))...))   with  sin()
  588.           applied 10 times.  Here we'll take z to be 1-i.  
  589.  
  590.                   > last = 1-i; every(n=1, 10, last = sin(last))
  591.  
  592.  
  593.      icalc                            -9-                       version 2.1
  594.  
  595.  
  596.      icalc                         User Guide                         icalc
  597.  
  598.  
  599.                           0.51856951608 - 0.01039404248 i
  600.  
  601.           Although every() and vevery() are useful in some situations,
  602.           most iterations are more easily performed by using Sum() and
  603.           Prod(). 
  604.  
  605.        multi(expr1, expr2, ... , exprN) 
  606.  
  607.           This special function still exists for upward compatability,
  608.           but it is syntactically  equivalent  to  the  C-style  block
  609.           introduced with version 2.0: 
  610.  
  611.                   { expr1 ; expr2 ; ... ; exprN; }
  612.  
  613.           (In  fact,  the semicolons can be omitted and new-lines used
  614.           instead - see the 'Advanced Guide').  
  615.  
  616.           The value of a call to multi or a block expression  is  that
  617.           of the  last  expression evaluated, namely exprN.  If output
  618.           has not been switched off with the 'silent' command, use  of
  619.           a block  will  print  the  result of it's last argument.  In
  620.           order to print the results of other expressions, the builtin
  621.           function print() is supplied.  print() takes  one  argument,
  622.           prints  it  to  the  display,  and returns its argument as a
  623.           result.  In this way, expressions can appear to return  more
  624.           than one result.  
  625.  
  626.           An   example:  write  a  function  that  converts  Cartesian
  627.           coordinates into polar form, returning the radius and  angle
  628.           in  degrees,  and setting the variables r and theta to these
  629.           values.  
  630.  
  631.  
  632.                   > func rec2pol(x,y) = {
  633.                   >      r=print(sqrt(x*x+y*y))
  634.                   >      theta=DEG*arg(x+i*y)
  635.                   > }
  636.  
  637.                   > rec2pol(3,4)
  638.                           5
  639.                           53.1301023542
  640.  
  641.  
  642.           Note the use of  complex  argument  to  obtain  the  correct
  643.           quadrant.  
  644.  
  645.  
  646.      ›1mOther features 
  647.  
  648.           ›0m›3micalc  ›0mnow  has  a  full  complement  of  common programming
  649.           constructs (C-style) such as if-else, for-loops etc.    This
  650.           necessitated  the  addition  of  relational  operators >=, >
  651.           etc.  and logical operators &&, !  etc.  
  652.  
  653.           In  order  to  make  the  range   of   applications   wider,
  654.           single-dimensional  arrays may also be used in a very simple
  655.           manner.  
  656.  
  657.  
  658.  
  659.      icalc                            -10-                      version 2.1
  660.  
  661.  
  662.      icalc                         User Guide                         icalc
  663.  
  664.  
  665.           User-function arguments may be arrays, pointers to variables
  666.           and  even  expressions  (in  the  sense  of  expressions  to
  667.           'special'  functions)  although in this area, syntax differs
  668.           considerably from the C programming language.  
  669.  
  670.           All these and other extensions are very  useful  facilities,
  671.           but non-essential  for  simple  work.  They are described in
  672.           detail in the 'Advanced Guide'.  
  673.  
  674.  
  675.      ›1mCommands 
  676.  
  677.           ›0m›3micalc ›0mhas a few commands to make life easier.   One  or  two
  678.           commands take a string as an argument.  Strings are enclosed
  679.           in double-quotes,  e.g.   "hello", although you may drop the
  680.           trailing quote if  you  wish.    It  should  be  noted  that
  681.           commands   may   NOT   be  used  within  function  or  block
  682.           declarations.  
  683.  
  684.        bye 
  685.        quit 
  686.        exit 
  687.           not surprisingly, these commands terminate ›3micalc.  
  688.  
  689.        ›0msilent 
  690.           stops generation of any further output.  However, errors and
  691.           warnings are  still   displayed.      It   is   useful   for
  692.           initialization files containing lots of definitions.  
  693.  
  694.        verbose 
  695.           restores generation of output.  
  696.  
  697.        help 
  698.           reminds you what other commands are available.  
  699.  
  700.        vars 
  701.           lists  all currently defined variables and their values, and
  702.           allocated arrays.  
  703.  
  704.        consts 
  705.           lists all predefined constants and their values.  
  706.  
  707.        builtins 
  708.           lists all built-in functions  available,  including  special
  709.           functions.  
  710.  
  711.        functions 
  712.           lists  all  user-defined  functions,  with  their  parameter
  713.           lists.  
  714.  
  715.        echo <string> 
  716.           simply prints given string (like Shell echo command).  
  717.  
  718.        pwd 
  719.           prints the current directory of ›3micalc.  
  720.  
  721.        ›0mcd <new-directory> 
  722.           changes current directory of ›3micalc.  ›0mEg. cd "s:" 
  723.  
  724.  
  725.      icalc                            -11-                      version 2.1
  726.  
  727.  
  728.      icalc                         User Guide                         icalc
  729.  
  730.  
  731.  
  732.        exec <command-string> 
  733.           executes command as if it had been typed  in  a  Shell.  Eg.
  734.           exec "ed  s:icalc.init".    If  ›3micalc  ›0mis  started  from the
  735.           Workbench,  output  from  exec'd  commands  will   only   be
  736.           displayed  if you are using AmigaDos 2.0 or above (this is a
  737.           compiler/OS bug).  
  738.  
  739.        read <file> 
  740.           reads and evaluates contents of named file (in  same  manner
  741.           as  if  passed  on  command-line  to ›3micalc ›0mor as a Workbench
  742.           argument.  
  743.  
  744.        writevars <file> 
  745.           dumps all variables defined in  current  session  (including
  746.           arrays)  to  specified file, for subsequent restoration with
  747.           the read  command  at   another   session.      At   present
  748.           user-function  definitions  are  NOT  saved  (and  are never
  749.           likely to  be  in  future  versions).    The  file   is   in
  750.           human-readable form.  
  751.  
  752.           There  are  a  couple  of  other  commands  detailed  in the
  753.           'Advanced Guide'.  
  754.  
  755.  
  756.      ›1mBugs 
  757.  
  758.           ›0mOne major bug was fixed in release 1.1a - the sqrt() builtin
  759.           was  not  returning  values   in   the   correct   quadrant.
  760.           Consequently, the inverse trigonometric functions, which are
  761.           defined using  sqrt(),  broke.  This has now been corrected.
  762.           Thanks to Pierre Ardichvili for pointing this out.  (Version
  763.           1.1a fixed this bug, but wasn't widely  distributed  because
  764.           version 2.0 was (supposedly) imminent.) 
  765.  
  766.           From  version  2.1, new routines were written to replace the
  767.           ones supplied with  the  SAS/C  compiler  (specifically  the
  768.           scanf  and  printf  "%g"  routines)  thus  removing all bugs
  769.           associated with these routines (such as  printing  "0."  and
  770.           "-0." amongst  others).  Thanks to Eric Rankin for reporting
  771.           the display bugs.  
  772.  
  773.           I hope that's all the major bugs ironed out, but  there  may
  774.           be the odd little bug in there somewhere -- if you find any,
  775.           PLEASE let me know and I'll try to fix them.  
  776.  
  777.           If  there's  something  you  hate about ›3micalc ›0mand would like
  778.           changed, or something you'd love that's not in,  drop  me  a
  779.           line (at the address below), or email me.  
  780.  
  781.  
  782.      ›1mSource 
  783.  
  784.           ›0m›3micalc  ›0mwas  written  in  C, and compiled with SAS/C (version
  785.           5.10a). Berkeley Yacc was used to generate the parser.   The
  786.           source  to version 2.1 of ›3micalc ›0mis available on request, for
  787.           a small fee.  See the 'ReadMe.First'  document  for  further
  788.           details.  
  789.  
  790.  
  791.      icalc                            -12-                      version 2.1
  792.  
  793.  
  794.      icalc                         User Guide                         icalc
  795.  
  796.  
  797.      ›1mCredits 
  798.  
  799.           ›0mThanks  to  the  authors  of  Berkeley  Yacc (it makes these
  800.           things so much easier to write and modify) and to SAS for  a
  801.           (fairly) stable C compiler.  
  802.  
  803.           Thanks  also  to  Steve Koren for Sksh, and Mike Meyer et al
  804.           for  Mg3;   together   they   make   a   great   development
  805.           environment.  
  806.  
  807.           Jeremy  McDonald  provided  me with a routine for displaying
  808.           numbers in any base (from 2 to 36) which has  been  used  as
  809.           the  core  of the number-displaying routine used in ›3micalc ›0m--
  810.           thanks Jeremy!  
  811.  
  812.           Many of the algorithms used in the sample script-files  that
  813.           come with ›3micalc ›0mwere based on those in "Numerical Recipes in
  814.           C", by  Press  et  al.   The book is very readable, and well
  815.           worth obtaining if you  use  numerical  algorithms  in  your
  816.           work.  
  817.  
  818.           This  was  my  first  yacc-based project, and I learnt a lot
  819.           from "The Unix Programming Environment" by  Brian  Kernighan
  820.           and Rob Pike. Their "hoc" taught me a lot about using Yacc.  
  821.  
  822.           Most  of  all, thanks to those people who have written to me
  823.           regarding icalc, for their comments and contributions.  
  824.  
  825.  
  826.      ›1mDistribution 
  827.  
  828.           ›0m›3micalc ›0mis freeware, copyrighted  software.    This  copyright
  829.           applies to  all  files  in  the ›3micalc ›0mdistribution.  You are
  830.           permitted to distribute it at only a nominal charge to cover
  831.           costs.  All files should be included unmodified.   Under  no
  832.           circumstances should ›3micalc ›0mbe sold for profit.  
  833.  
  834.  
  835.      ›1mThe Bottom Line 
  836.  
  837.           ›0mAlthough ›3micalc ›0mis not shareware, contributions would be most
  838.           welcome,  as  I'm a poor student, and have put a lot of work
  839.           into this project.  But they're NOT required - bug  reports,
  840.           praise, suggestions,  neat  programs  etc.  are welcome (and
  841.           indeed encouraged) with or without contribution.  Thanks  to
  842.           those kind people (small in number) who have written to me.  
  843.  
  844.           I can be contacted via snail mail at: 
  845.  
  846.                   Martin W. Scott,
  847.                   23 Drum Brae North,
  848.                   Edinburgh, EH4 8AT
  849.                   United Kingdom.
  850.  
  851.           or you can email me; my address is mws@castle.ed.ac.uk 
  852.  
  853.           Thanks for  reading  this  far.  The appendices follow; some
  854.           details in them will not have been covered in this document,
  855.  
  856.  
  857.      icalc                            -13-                      version 2.1
  858.  
  859.  
  860.      icalc                         User Guide                         icalc
  861.  
  862.  
  863.           but are explained in the 'Advanced Guide'.  
  864.  
  865.  
  866.  
  867.  
  868.  
  869.  
  870.  
  871.  
  872.  
  873.  
  874.  
  875.  
  876.  
  877.  
  878.  
  879.  
  880.  
  881.  
  882.  
  883.  
  884.  
  885.  
  886.  
  887.  
  888.  
  889.  
  890.  
  891.  
  892.  
  893.  
  894.  
  895.  
  896.  
  897.  
  898.  
  899.  
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.      icalc                            -14-                      version 2.1
  924.  
  925.  
  926.      icalc                         User Guide                         icalc
  927.  
  928.  
  929.      ›1mAppendix 1 ›0m- ›1mOperators ›0m(›1min increasing order of precedence›0m) 
  930.  
  931.  
  932.           =  +=  -=  *=  /=   assignment
  933.           ?:                  ternary operator 
  934.           ||                  logical or
  935.           &&                  logical and
  936.           ==  !=              equal, not equal
  937.           >  >=  <  <=        greater-than etc.
  938.           +  -                addition, subtraction
  939.           *  /                multiplication, division
  940.           -  !                unary minus, logical not
  941.           ^                   exponentation
  942.           '                   conjugate operator
  943.  
  944.  
  945.      ›1mAppendix 2 ›0m- ›1mConstants 
  946.  
  947.  
  948.           ›0mABASE               index of first element for arrays
  949.           DEG                 Number of degrees in one radian
  950.           E                   exp(1)
  951.           FALSE               0
  952.           GAMMA               Euler's constant, 0.57721566...
  953.           INFINITY            (almost) the largest real number possible 
  954.           LOG10               ln(10)
  955.           LOG2                ln(2)
  956.           PHI                 Golden ratio 1.61803398...
  957.           PI                  4*atan(1) (that's one definition)
  958.           TRUE                1
  959.  
  960.  
  961.      ›1mAppendix 3 ›0m- ›1mKeywords 
  962.  
  963.  
  964.           ›0mfunc                function declaration
  965.           array               (external) array definition
  966.           local               local variable definition
  967.           return              return from function
  968.  
  969.           if-else             control-flow constructs
  970.           while-do
  971.           do-while                
  972.           for                     
  973.  
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.  
  989.      icalc                            -15-                      version 2.1
  990.  
  991.  
  992.      icalc                         User Guide                         icalc
  993.  
  994.  
  995.      ›1mAppendix 4 ›0m- ›1mBuiltin functions 
  996.  
  997.  
  998.           ›0mParameters are evaluated from left to write.
  999.           Parameters shown:
  1000.  
  1001.                   z implies complex number expected,
  1002.                   x implies real number expected,
  1003.                   n implies integer expected.
  1004.                   a implies array identifier expected.
  1005.  
  1006.           Conversions will be made if required.
  1007.  
  1008.           Functions you think missing below may well be defined in one of
  1009.           the support scripts.
  1010.  
  1011.  
  1012.           ›1mSingle›0m-›1margument functions›0m:        
  1013.  
  1014.           sin(z)              trigonometric functions
  1015.           cos(z)
  1016.           tan(z)
  1017.  
  1018.           asin(z)             inverse trigonometric functions
  1019.           acos(z)
  1020.           atan(z)
  1021.  
  1022.           sinh(z)             hyperbolic trigonometric functions
  1023.           cosh(z)
  1024.           tanh(z)
  1025.  
  1026.           exp(z)              exponential function
  1027.           ln(z)               natural logarithm
  1028.           sqr(z)              square
  1029.           sqrt(z)             square root
  1030.  
  1031.           conj(z)             conjugate (see also ' operator)
  1032.           abs(z)              absolute value (sqrt(norm(z))
  1033.           norm(z)             not really norm; if z=x+iy, norm(z) = x²+y²
  1034.           arg(z)              principal argument (in (-PI,PI])
  1035.           Re(z)               real part of complex number
  1036.           Im(z)               imaginary part of complex number
  1037.  
  1038.           ceil(x)             ceil of real part (eg. ceil(1.2) = 2)
  1039.           floor(x)            floor of real part (eg. floor(1.2) = 1)
  1040.           int(x)              return real part rounded to nearest integer
  1041.           sgn(x)              sign of real part (eg. sgn(-1.6) = -1)
  1042.  
  1043.           time(x)             system time in seconds, less its argument
  1044.           print(z)            prints and returns value of its argument
  1045.           prec(n)             adjust number of significant figures displayed
  1046.           sigzeros(n)         set # of leading zeros considered significant 
  1047.           error(n)            abort evaluation with error n
  1048.           outbase(n)          print numbers using base-n
  1049.  
  1050.  
  1051.  
  1052.  
  1053.  
  1054.  
  1055.      icalc                            -16-                      version 2.1
  1056.  
  1057.  
  1058.      icalc                         User Guide                         icalc
  1059.  
  1060.  
  1061.           ›1mArray functions›0m:        
  1062.  
  1063.           display(a)          display contents of an array
  1064.           sizeof(a)           returns number of elements in array
  1065.           resize(a,n)         changes dimension of array to new size n
  1066.           arraybase(n)        change first index of arrays to n
  1067.                               (returns old base)
  1068.  
  1069.  
  1070.           ›1mSpecial functions›0m:        
  1071.  
  1072.           Sum                 calculate a finite sum
  1073.           Prod                calculate a finite product
  1074.           every               perform a general iteration quietly
  1075.           vevery              perform a general iteration verbosely
  1076.           multi               evaluate many expressions (defunct)
  1077.           min                 returns minimum real part in parameters
  1078.           max                 returns maximum real part in parameters
  1079.  
  1080.           min and max take an arbitrary number of arguments.
  1081.  
  1082.  
  1083.  
  1084.  
  1085.  
  1086.  
  1087.  
  1088.  
  1089.  
  1090.  
  1091.  
  1092.  
  1093.  
  1094.  
  1095.  
  1096.  
  1097.  
  1098.  
  1099.  
  1100.  
  1101.  
  1102.  
  1103.  
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.      icalc                            -17-                      version 2.1
  1122.  
  1123.